package com.party.core.service.order.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.common.utils.DateUtils;
import com.party.core.dao.read.order.RefundPlanReadDao;
import com.party.core.dao.write.order.RefundPlanWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.order.RefundPlan;
import com.party.core.service.order.IRefundPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 退款计划接口实现
 *
 * @Author: huangzequn
 * @Date: 2019/5/16 10:28
 */
@Service
public class RefundPlanService implements IRefundPlanService {

    @Autowired
    RefundPlanReadDao refundPlanReadDao;

    @Autowired
    RefundPlanWriteDao refundPlanWriteDao;

    /**
     * 退款计划插入
     * @param refundPlan 退款计划
     * @return 插入结果（true/false）
     */
    @Override
    public String insert(RefundPlan refundPlan) {
        BaseModel.preInsert(refundPlan);
        refundPlan.setStatus("1");//默认有效
        refundPlan.setPlanDate(DateUtils.addHour(DateUtils.getTodayDate(), 12));//12小时后才能执行
        boolean result = refundPlanWriteDao.insert(refundPlan);
        if (result) {
            return refundPlan.getId();
        }
        return null;
    }

    /**
     * 退款计划更新
     * @param refundPlan 退款计划
     * @return 更新结果（true/false）
     */
    @Override
    public boolean update(RefundPlan refundPlan) {
        return refundPlanWriteDao.update(refundPlan);
    }

    /**
     * 根据主键获取退款计划信息
     * @param id 主键
     * @return 退款计划
     */
    @Override
    public RefundPlan get(String id) {
        return refundPlanReadDao.get(id);
    }

    /**
     * 分页查询退款计划信息
     * @param refundPlan 退款计划
     * @param page 分页信息
     * @return 退款计划列表
     */
    @Override
    public List<RefundPlan> listPage(RefundPlan refundPlan, Page page) {
        return refundPlanReadDao.listPage(refundPlan, page);
    }

    /**
     * @Author hzq
     * @Description //根据projectId找到退款计划
     * @Date 11:15 2019/5/16
     * @param goalId
     * @return
     **/
    @Override
    public RefundPlan getByGoalId(String goalId) {
        return refundPlanReadDao.getByGoalId(goalId);
    }

    /**
     * @Author hzq
     * @Description //退款计划列表查询
     * @Date 16:40 2019/6/5
     * @param refundPlan
     * @param page
     * @param params
     * @return
     **/
    @Override
    public List<RefundPlan> webListPage(RefundPlan refundPlan, Page page, Map<String, Object> params) {
        return refundPlanReadDao.webListPage(refundPlan, page, params);
    }

    /**
     * @Author hzq
     * @Description //获取所有符合条件的退款计划
     * @Date 11:15 2019/5/16
     * @param refundPlan
     * @return
     **/
    @Override
    public List<RefundPlan> list(RefundPlan refundPlan) {
        return refundPlanReadDao.list(refundPlan);
    }

    @Override
    public List<RefundPlan> batchList(Set<String> ids, RefundPlan refundPlan, Page page) {
        return null;
    }

    @Override
    public boolean deleteLogic(String id) {
        return false;
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return refundPlanWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        return false;
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        return false;
    }


}
